package io.renren.modules.business.controller;


import java.util.Date;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.renren.modules.business.entity.ENoticeEntity;
import io.renren.modules.business.service.ENoticeService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 通知表
 * @date 2022-02-24 19:05:53
 */
@RestController
@RequestMapping("business/enotice")
public class ENoticeController {

    @Autowired
    private ENoticeService eNoticeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = eNoticeService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		ENoticeEntity eNotice = eNoticeService.getById(id);

        return R.ok().put("eNotice", eNotice);
    }

    /**
     * 通知列表查询
     * @param pageNum
     * @param pageSize
     * @param noticePubId
     * @param flag
     * @param orderType
     * @return
     */
    @GetMapping("/query")
    public R queryNoticeList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                             @RequestParam(value = "noticePubId", required = false) Long noticePubId,
                             @RequestParam(value = "flag", defaultValue = "1") Integer flag,
                             @RequestParam(value = "orderType", defaultValue = "1") String orderType) {
        return R.ok().put("page", eNoticeService.queryNoticeList(pageNum, pageSize, noticePubId, flag, orderType));
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody ENoticeEntity eNotice){
		eNoticeService.save(eNotice);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody ENoticeEntity eNotice){
        eNotice.setNoticePubTime(new Date());
		eNoticeService.updateById(eNotice);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestParam("id") Long id){
		eNoticeService.removeById(id);

        return R.ok();
    }

}
